package cn.lichenfei.fxui.controls.skin;

import cn.lichenfei.fxui.controls.CFPagination;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.scene.control.Label;
import javafx.scene.control.SkinBase;
import javafx.scene.layout.HBox;

public class CFPaginationSkin extends SkinBase<CFPagination> {

    private final MyLabel total;
    private final MyLabel pages;
    private final MyLabel pageSize;
    private final HBox container;

    public CFPaginationSkin(CFPagination control) {
        super(control);
        //布局
        total = new MyLabel("总数: %s");
        pages = new MyLabel("总页数: %s");
        pageSize = new MyLabel("页容: %s");
        container = new HBox();
        container.getChildren().setAll(total, pageSize);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void layoutChildren(final double x, final double y,
                                  final double w, final double h) {
        super.layoutChildren(x, y, w, h);
    }

    private class MyLabel extends Label {
        private IntegerProperty value = new SimpleIntegerProperty(0);

        public MyLabel(String format) {
            textProperty().bind(value.asString(format));
        }

        public IntegerProperty valueProperty() {
            return value;
        }
    }
}
